home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / net / amitcp2_x_gcc.lha / RCS.RCSfiles / autoinit.c,v next >
Text File  |  1994-02-03  |  6KB  |  340 lines

  1. head    1.7;
  2. access;
  3. symbols;
  4. locks
  5.     jasegler:1.7; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.7
  10. date    94.02.04.01.47.09;    author jasegler;    state Exp;
  11. branches;
  12. next    1.6;
  13.  
  14. 1.6
  15. date    94.02.04.01.35.31;    author jasegler;    state Exp;
  16. branches;
  17. next    1.5;
  18.  
  19. 1.5
  20. date    94.01.12.20.34.49;    author jasegler;    state Exp;
  21. branches;
  22. next    1.4;
  23.  
  24. 1.4
  25. date    94.01.12.18.30.46;    author jasegler;    state Exp;
  26. branches;
  27. next    1.3;
  28.  
  29. 1.3
  30. date    94.01.11.21.02.00;    author jasegler;    state Exp;
  31. branches;
  32. next    1.2;
  33.  
  34. 1.2
  35. date    94.01.11.20.20.26;    author jasegler;    state Exp;
  36. branches;
  37. next    1.1;
  38.  
  39. 1.1
  40. date    94.01.11.18.54.43;    author jasegler;    state Exp;
  41. branches;
  42. next    ;
  43.  
  44.  
  45. desc
  46. @@
  47.  
  48.  
  49. 1.7
  50. log
  51. @*** empty log message ***
  52. @
  53. text
  54. @char RCS_ID_AUTOINIT_C[] = "$Id: autoinit.c,v 1.6 1994/02/04 01:35:31 jasegler Exp jasegler $";
  55. /*
  56.  * autoinit.c --- SAS C auto initialization functions
  57.  *
  58.  * Author: ppessi <Pekka.Pessi@@hut.fi>
  59.  *
  60.  * Copyright © 1993 AmiTCP/IP Group, <amitcp-group@@hut.fi>
  61.  *                  Helsinki University of Technology, Finland.
  62.  *                  All rights reserved.
  63.  *
  64.  * Created      : Sat Mar 20 03:31:29 1993 ppessi
  65.  * Last modified: Mon Jul 19 14:24:30 1993 jraja
  66.  *
  67.  */
  68.  
  69. #include <dos/dos.h>
  70. #include <sys/types.h>
  71. #include <devices/timer.h>
  72. #include <exec/types.h>
  73. #include <exec/libraries.h>
  74.  
  75. #include <intuition/intuition.h>
  76.  
  77. #ifdef __GNUC__            /* C= include files only have clib not Sux's (SASC) proto files :) */
  78. #include <clib/exec_protos.h>
  79. #include <clib/intuition_protos.h>
  80. #include <clib/socket_protos.h>
  81. #include <signal.h>
  82. #elif _DCC
  83. #include <clib/socket_protos.h>
  84. #include <clib/exec_protos.h>
  85. #include <clib/intuition_protos.h>
  86. #elif __SASC__
  87. #include <proto/socket.h>
  88. #include <proto/exec.h>
  89. #include <proto/intuition.h>
  90. #endif
  91.  
  92. #include <stdio.h>
  93. #include <stdlib.h>
  94.  
  95. struct Library *SocketBase = NULL;
  96.  
  97. int errno = 0;            /* global errno variable */
  98.  
  99. STRPTR SOCKETNAME = "bsdsocket.library";
  100.  
  101. #define SOCKETVERSION 2        /* minimum bsdsocket version to use */
  102.  
  103. #ifdef __SASC__
  104. extern STRPTR _ProgramName;    /* SAS startup module defines this :-) */
  105. #endif
  106.  
  107. #ifdef __GNUC__
  108. char _ProgramName[] = "GNU C Program";
  109. #endif
  110.  
  111. #ifdef _DCC
  112. char _ProgramName[] = "DCC Program";
  113. #endif
  114.  
  115. /****** amiga.lib/autoinit *********************************************
  116.  
  117.  *   NAME
  118.  *       autoinit - SAS C Autoinitialization Functions
  119.  *
  120.  *   SYNOPSIS
  121.  *       _STIopenSockets()
  122.  *
  123.  *       void _STIopenSockets(void)
  124.  *
  125.  *       _STDcloseSockets()
  126.  *
  127.  *       void _STDcloseSockets(void)
  128.  *
  129.  *   FUNCTION
  130.  *       These functions open and close the bsdsocket.library at the
  131.  *       startup and exit of the program, respectively. For a
  132.  *       program to use these functions, it must be linked with
  133.  *       netlib:net.lib.
  134.  *
  135.  *       If the library can be opened, the _STIopenSockets() calls
  136.  *       bsdsocket.library function SetErrnoPtr() to tell the
  137.  *       library the address and the size of the errno variable of
  138.  *       the calling program.
  139.  *
  140.  *   NOTES
  141.  *       _STIopenSockets() also checks that the system version is at
  142.  *       least 37. It puts up a requester if the bsdsocket.library
  143.  *       is not found or is of wrong version.
  144.  *
  145.  *       The autoinitialization and autotermination functions are
  146.  *       features specific to the SAS C6. However, these functions
  147.  *       can be used with other (ANSI) C compilers, too. Example
  148.  *       follows:
  149.  *
  150.  *       \* at start of main() *\
  151.  *
  152.  *       atexit(_STDcloseSockets);
  153.  *       _STDopenSockets();
  154.  *
  155.  *   BUGS
  156.  *
  157.  *   SEE ALSO
  158.  *       bsdsocket.library/SetErrnoPtr(),
  159.  *       SAS/C 6 User's Guide p. 145 for details of
  160.  *       autoinitialization and autotermination functions.
  161.  *****************************************************************************
  162.  *
  163.  */
  164.  
  165. void
  166. _STIopenSockets (void)
  167. {
  168.   static short done = 0;
  169. #ifdef __SASC__
  170.   struct Library *IntuitionBase;
  171. #endif
  172.   STRPTR errorStr;
  173.  
  174.   if (done++)            /* try only once (SAS/C 6.2 liked to call this twice) */
  175.     return;
  176.  
  177.   /*
  178.    * Check OS version
  179.    */
  180.   if ((*(struct Library **) 4)->lib_Version < 37)
  181.     exit (20);
  182.  
  183.   /*
  184.    * Open bsdsocket.library
  185.    */
  186.   if ((SocketBase = OpenLibrary (SOCKETNAME, SOCKETVERSION)) != NULL)
  187.     {
  188.       /*
  189.          * Succesfull. Now tell bsdsocket.library the address of our errno
  190.        */
  191.       SetErrnoPtr (&errno, sizeof (errno));
  192.  
  193.       return;
  194.     }
  195.   else
  196.     {
  197.       errorStr = "AmiTCP/IP version 2 or later must be started first.";
  198.     }
  199.  
  200. #ifdef __SASC__
  201.   IntuitionBase = OpenLibrary ("intuition.library", 36);
  202.  
  203.   if (IntuitionBase != NULL)
  204.     {
  205.       struct EasyStruct libraryES;
  206.  
  207.       libraryES.es_StructSize = sizeof (libraryES);
  208.       libraryES.es_Flags = 0;
  209.       libraryES.es_Title = _ProgramName;
  210.       libraryES.es_TextFormat = errorStr;
  211.       libraryES.es_GadgetFormat = "Exit %s";
  212.  
  213.       EasyRequestArgs (NULL, &libraryES, NULL, (APTR) & _ProgramName);
  214.  
  215.       CloseLibrary (IntuitionBase);
  216.     }
  217.   exit (20);
  218. #endif
  219.  
  220. #ifdef __GNUC__
  221.   fprintf (stderr, "%s\n\n", errorStr);
  222.   exit (20);
  223. #endif
  224. }
  225.  
  226. void
  227. _STDcloseSockets (void)
  228. {
  229.   if (SocketBase)
  230.     {
  231.       CloseLibrary (SocketBase);
  232.       SocketBase = NULL;
  233.     }
  234. }
  235.  
  236. #ifdef __GNUC__
  237.  
  238. static void
  239. constructor ()
  240. {
  241.   _STIopenSockets ();
  242.   SetSocketSignals (SIGBREAKF_CTRL_C, SIGIO, SIGURG);
  243. }
  244.  
  245. static void
  246. destructor ()
  247. {
  248.   _STDcloseSockets ();
  249. }
  250.  
  251. asm ("  .text;  .stabs \"___CTOR_LIST__\",22,0,0,_constructor");
  252. asm ("  .text;  .stabs \"___DTOR_LIST__\",22,0,0,_destructor");
  253.  
  254. #endif /* GNUC Auto openers */
  255. @
  256.  
  257.  
  258. 1.6
  259. log
  260. @*** empty log message ***
  261. @
  262. text
  263. @d1 1
  264. a1 1
  265. char RCS_ID_AUTOINIT_C[] = "$Id: autoinit.c,v 1.5 1994/01/12 20:34:49 jasegler Exp jasegler $";
  266. d168 2
  267. a169 2
  268.   fprintf (stderr, errorStr);
  269.   abort ();
  270. @
  271.  
  272.  
  273. 1.5
  274. log
  275. @*** empty log message ***
  276. @
  277. text
  278. @d1 1
  279. a1 1
  280. char RCS_ID_AUTOINIT_C[] = "$Id: autoinit.c,v 1.4 1994/01/12 18:30:46 jasegler Exp jasegler $";
  281. d39 1
  282. d116 1
  283. d118 1
  284. d143 3
  285. a145 1
  286.     errorStr = "AmiTCP/IP version 2 or later must be started first.";
  287. d147 1
  288. d165 6
  289. @
  290.  
  291.  
  292. 1.4
  293. log
  294. @..
  295. @
  296. text
  297. @d1 1
  298. a1 1
  299. char RCS_ID_AUTOINIT_C[] = "$Id: autoinit.c,v 1.3 1994/01/11 21:02:00 jasegler Exp jasegler $";
  300. d16 2
  301. d28 1
  302. d177 1
  303. @
  304.  
  305.  
  306. 1.3
  307. log
  308. @*** empty log message ***
  309. @
  310. text
  311. @d1 1
  312. a1 1
  313. char RCS_ID_C[] = "$Id: autoinit.c,v 1.2 1994/01/11 20:20:26 jasegler Exp jasegler $";
  314. @
  315.  
  316.  
  317. 1.2
  318. log
  319. @*** empty log message ***
  320. @
  321. text
  322. @d1 1
  323. a1 1
  324. char RCS_ID_C[] = "$Id: autoinit.c,v 1.1 1994/01/11 18:54:43 jasegler Exp $";
  325. d167 19
  326. @
  327.  
  328.  
  329. 1.1
  330. log
  331. @Initial revision
  332. @
  333. text
  334. @d1 1
  335. a1 1
  336. char RCS_ID_C[] = "$Id: autoinit.c,v 1.9 1993/07/19 11:24:40 jraja Exp $";
  337. d46 1
  338. d48 9
  339. @
  340.